
local BlurDialog = class( "BlurDialog", function()
    return display.newNode()
end)

BlurDialog.blurNode = nil
BlurDialog.beforeBlurCallback = nil
BlurDialog.afterBlurCallback = nil
BlurDialog.finishBlurCallback = nil

function BlurDialog:ctor()
    self:setContentSize(cc.size(display.width,display.height))

    -- 创建blurDialog
    if cc.isDead( self._blurBackgroudNode ) then -- 为空、被销毁？
        -- release_print( " --------------->>>>> self._blurBackgroudNode 创建" )
        self._blurBackgroudNode = custom.BlurBackgroudNode:create()
        self._blurBackgroudNode:setName( "m_blurBackgroudNode" )
        self._blurBackgroudNode:setContentSize(cc.size(display.width,display.height))
        self._blurBackgroudNode:setTouchEnabled(true)
        self._blurBackgroudNode:setSwallowTouches(true)
        self:addChild( self._blurBackgroudNode )
    end

    -- 处理回调事件
    if  self._blurBackgroudNode.setEventCallback then -- 存在事件处理回调函数？
        self._blurBackgroudNode:setEventCallback(function(befor)
            if befor then
                if BlurDialog.beforeBlurCallback then
                    BlurDialog.beforeBlurCallback()
                end
            else
                if BlurDialog.afterBlurCallback then
                    BlurDialog.afterBlurCallback()
                end
            end
        end)
    end

    -- 设置渲染目标节点
    local blurNode = BlurDialog.blurNode or cc.Director:getInstance():getRunningScene()
    if blurNode then
        -- release_print( " --------------->>>>> self._blurBackgroudNode 设置渲染节点" )
        self._blurBackgroudNode:setBlurTargetNode( blurNode )
    end

    -- 退出回调
    self:onNodeEvent("exit", function()
        -- release_print( " --------------->>>>> self._blurBackgroudNode 销毁" )

        if BlurDialog.finishBlurCallback then
            BlurDialog.finishBlurCallback()
        end
    end)
end

return BlurDialog
